package com.example.administrator.waitan.hot.week;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.LruCache;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;
import com.example.administrator.waitan.R;
import com.example.administrator.waitan.tools.VolleySingleton;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/1/12.
 */
public class WeekBaseAdapter extends BaseAdapter {
    private List<WeekInfo> data;
    private Context context;
    private ImageLoader imageLoader;
    private ImageLoader.ImageCache imageCache;
    private LruCache<String,Bitmap> lruCache;
    private RequestQueue queue;
    public WeekBaseAdapter(List<WeekInfo> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        MyViewHolder myViewHolder;
        if (view == null){
            view = LayoutInflater.from(context).inflate(R.layout.item_lv_week,null);
            myViewHolder = new MyViewHolder();
            myViewHolder.title = (TextView) view.findViewById(R.id.tv_item_week_title);
            myViewHolder.name = (TextView) view.findViewById(R.id.tv_item_week_name);
            myViewHolder.date = (TextView) view.findViewById(R.id.tv_item_week_date);
            myViewHolder.pic = (ImageView) view.findViewById(R.id.iv_item_week_pc);
            view.setTag(myViewHolder);
        }
        else{
            myViewHolder = (MyViewHolder) view.getTag();
        }
        myViewHolder.title.setText(data.get(i).getTitle());
        myViewHolder.name.setText(data.get(i).getAuthor_name());
        myViewHolder.date.setText(data.get(i).getDisplay_date());
        VolleySingleton.getImageLoader().get(data.get(i).getThumbnail(),VolleySingleton.getImageListener(myViewHolder.pic));
        return view;
    }
    private class MyViewHolder{
        TextView title,name,date;
        ImageView pic;
    }
}
